"""
登录页面
"""

from selenium.webdriver.common.by import By
from page.base_page import BasePage
class LoginPage(BasePage):
    #   元素定位器
    url="http://192.168.1.25/crm/index.php?m=user&a=login"
    username_locator = (By.NAME,"name")
    password_locator = (By.NAME,"password")
    btn_locator = (By.NAME,'submit')

    # def __init__(self,driver):
    #     self.driver = driver
    # 操作方法
    # 输入用户名
    # def open(self):
    #     self.driver.get(self.url)
    def input_username(self, username):
        self.driver.find_element(*self.username_locator).send_keys(username)

    #输入密码
    def input_password(self, password):
        self.driver.find_element(*self.password_locator).send_keys(password)

    #点击确定
    def click_btn(self):
        self.driver.find_element(*self.btn_locator).click()

    #登录页面
    """完成登录操作"""
    def login(self,username,password):
        self.open()
        self.input_username(username)
        self.input_password(password)
        self.click_btn()

    #cookie

    def cookie(self):
        cookie = {"name": "PHPSESSID",
                  "value": "d6c61a2bnhioq9228jfp76g392"}  # 已经获取value的值

        self.driver.get("http://192.168.1.25/")  # 每次要先访问主机
        self.driver.add_cookie(cookie)  # 实例化
        self.driver.get("http://192.168.1.25/crm/index.php?m=index&a=index")
